Declare libraries
library(raster)
## Loading required package: sp
library(rhdf5)
library(rgdal)
## rgdal: version: 1.1-10, (SVN revision 622)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 1.11.4, released 2016/01/25
## Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgdal/gdal
## Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
## Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgdal/proj
## Linking to sp version: 1.2-3
Import Canopy Height Model
chm<- raster("../NEONdata/D17-California/TEAK/2013/lidar/TEAK_lidarCHM.tif")
plot(chm, main=" this plots using the raster package")

image(chm, main= "these are just pixels and will stretch the space")

Deal with 0 values
old.hist<-hist(chm)
## Warning in .hist1(x, maxpixels = maxpixels, main = main, plot = plot, ...):
## 32% of the raster cells were used. 100000 values used.

plot(old.hist)

chm[chm==0]<- NA
hist(chm, xlab= "Tree Height (m)")

Import aspect data
aspect<- raster("../NEONdata/D17-California/TEAK/2013//lidar//TEAK_lidarAspect.tif")
plot(aspect, main= "Aspect data for Teakette Field Site")

Create Classification Matrix
#create string of values
# by creating a matrix
class.m<- c(0, 45, 1,
45, 135, NA,
135, 225, 2,
225, 315, NA,
315, 360, 1)
rcl.m<- matrix(class.m,
ncol=3,
byrow=TRUE)
rcl.m
## [,1] [,2] [,3]
## [1,] 0 45 1
## [2,] 45 135 NA
## [3,] 135 225 2
## [4,] 225 315 NA
## [5,] 315 360 1
reclassify raster
asp.ns <- reclassify(aspect, rcl.m)
plot(asp.ns,
main= "North and South Facing Slopes")

Export Geotiff
writeRaster(asp.ns,
file="../NEONdata//D17-California//outputs//TEAK/Teak_nsAspect2.tif",
options= "COMPRESS= LZW",
NAflag= -9999)
Mask Data
asp.ns
## class : RasterLayer
## dimensions : 577, 543, 313311 (nrow, ncol, ncell)
## resolution : 1, 1 (x, y)
## extent : 325963, 326506, 4102905, 4103482 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=utm +zone=11 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
## data source : in memory
## names : layer
## values : 0, 2 (min, max)
ndvi<- raster("../NEONdata//D17-California//TEAK//2013//spectrometer//veg_index//TEAK_NDVI.tif")
plot(ndvi,
main= "NDVI for Teakettle Field Site")

#mask data
nFacing.ndvi<- mask(ndvi,
asp.ns)
plot(nFacing.ndvi)
